import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:geomancy/styles/index.dart';
import 'package:geomancy/tools/constant.dart';
import 'package:geomancy/widgets/common_btn.dart';
import 'package:geomancy/widgets/common_header.dart';
import 'package:geomancy/widgets/stroke_text.dart';
import 'package:go_router/go_router.dart';

class GoodDayPage extends StatefulWidget {
  const GoodDayPage({super.key});

  @override
  State<GoodDayPage> createState() => _GoodDayPageState();
}

class _GoodDayPageState extends State<GoodDayPage> {
  int tabIndex = 0;
  List<String> wordsList = ['嫁娶', '祭祀', '动土', '开市', '开光', '祈福', '求嗣', '出行', '移徒', '安床', '拆卸', '修造', '安门', '挂匾', '纳财', '扫舍'];
  int? wordIndex;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CommonHeader.appBar(context: context),
      backgroundColor: ColorStyle.pageDefaultColor,
      body: ListView(
        padding: EdgeInsets.fromLTRB(Constant.PAGEPADDING.w, 20.w, Constant.PAGEPADDING.w, 40.w),
        children: [
          Wrap(
            alignment: WrapAlignment.center,
            spacing: 6.w,
            children: [
              GestureDetector(
                onTap: () {
                  setState(() {
                    tabIndex = 0;
                  });
                },
                child: Container(
                  width: 252.w,
                  height: 80.w,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                      color: tabIndex == 0 ? ColorStyle.themeColor : ColorStyle.themeLightColor,
                      border: Border.all(width: 5.w, color: ColorStyle.borderColor),
                      borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(40.w),
                        bottomLeft: Radius.circular(40.w),
                        topRight: Radius.circular(15.w),
                        bottomRight: Radius.circular(15.w),
                      )
                  ),
                  child: StrokeText(txt: '宜', fontSize: 30.sp, color: ColorStyle.themeLightColor),
                ),
              ),
              GestureDetector(
                onTap: () {
                  setState(() {
                    tabIndex = 1;
                  });
                },
                child: Container(
                  width: 252.w,
                  height: 80.w,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                      color: tabIndex == 1 ? ColorStyle.themeColor : ColorStyle.themeLightColor,
                      border: Border.all(width: 5.w, color: ColorStyle.borderColor),
                      borderRadius: BorderRadius.only(
                        topRight: Radius.circular(40.w),
                        bottomRight: Radius.circular(40.w),
                        topLeft: Radius.circular(15.w),
                        bottomLeft: Radius.circular(15.w),
                      )
                  ),
                  child: StrokeText(txt: '忌', fontSize: 30.sp, color: ColorStyle.themeLightColor),
                ),
              )
            ],
          ),
          Container(
            margin: EdgeInsets.only(top: 20.w, bottom: 100.w),
            padding: EdgeInsets.symmetric(horizontal: 35.w, vertical: 45.w),
            decoration: BoxDecoration(
              color: ColorStyle.themeLightColor,
              border: Border.all(width: 5.w, color: ColorStyle.borderColor),
              borderRadius: BorderRadius.all(Radius.circular(60.w))
            ),
            child: Wrap(
              spacing: 6.w,
              runSpacing: 7.w,
              alignment: WrapAlignment.start,
              children: wordsList.asMap().keys.map((index) {
                return GestureDetector(
                  onTap: () {
                    setState(() {
                      wordIndex = index;
                    });
                  },
                  child: Container(
                    width: 192.w,
                    height: 90.w,
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      color: wordIndex == index ? ColorStyle.themeColor : const Color.fromRGBO(219, 207, 174, 1),
                      borderRadius: BorderRadius.all(Radius.circular(20.w)),
                    ),
                    child: Text(wordsList[index], style: TextStyle(fontSize: 30.sp, color: tabIndex == 0 ? ColorStyle.textColor : ColorStyle.red),)
                  ),
                );
              }).toList(),
            ),
          ),
          Center(child: CommonBtnWidget(txt: '查询', size: Size(590.w, 80.w), onTap: () {
            if (wordIndex == null) {
              return;
            }
            context.push('/good_day_result', extra: {
              "type": wordsList[wordIndex!],
              "status": tabIndex == 0 ? 'y' : 'j'
            });
          }))
        ],
      ),
    );
  }
}
